let slider2 = new Slider("slider2");
slider2.addBtn();
slider2.addCircle();
let oBtn = document.querySelector(".main-right");
let btn = document.querySelector("#top");
window.onscroll = function () {
  var st = document.documentElement.scrollTop || document.body.scrollTop;
  if (st >= 80) {
    oBtn.style.display = "block";
  } else {
    oBtn.style.display = "none";
  }
};
btn.onclick = function () {
  document.documentElement.scrollTop = document.body.scrollTop = 0;
  return false;
};
let oBis = document.querySelector("#che");
// let oBin = document.querySelector("#xian");
oBis.onclick = function (e) {
  var evt = e || event;
  evt.preventDefault();
  evt.returnValue = false;
  // return false;
};
// oBin.onclick = function (e) {
//   var evt = e || event;
//   evt.preventDefault();
//   // evt.returnValue = false;
//   // evt.stopPropagation();

//   // return false;
// };
$(function () {
  // $($(".dian")[1]).width(100);
  $(".enrers-two").css({ display: "none" });
  $(".enrers-four").css({ display: "none" });
  $(".enrers-six").css({ display: "none" });
  $(".enrers-seven").css({ display: "none" });
  $(".focus_twos").css({ display: "none" });
  $(".new-launch-two").css({ display: "none" });
  $(".nix-one").css({ display: "none" });
  $(".boss").css({ display: "none" });
  $(".register").click(function (e) {
    $(".boss").css({ display: "block" });
    event.stopPropagation();
    e.preventDefault();
  });
  $(window).click(function (e) {
    $(".boss").css({ display: "none" });
    e.stopPropagation();
  });
  $(".boss").click(function (e) {
    event.stopPropagation();
    e.preventDefault();
  });
  $(".poi h3")
    .eq(0)
    .mouseover(function () {
      $(".line-vv").stop().animate({ left: "0px", width: "93px" }, 350);
    });
  $(".poi h3")
    .eq(1)
    .mouseover(function () {
      $(".line-vv").stop().animate({ left: "100px", width: "93px" }, 350);
    });
  $(".poi h3")
    .eq(0)
    .click(function () {
      $(".line-gg").stop().animate({ left: "0px", width: "93px" }, 350);
      $(".nix-one").css({ display: "block" });
      $(".nix-two").css({ display: "none" });
    });
  $(".poi h3")
    .eq(1)
    .click(function () {
      $(".line-gg").stop().animate({ left: "100px", width: "93px" }, 350);
      $(".nix-one").css({ display: "none" });
      $(".nix-two").css({ display: "block" });
    });
  $("#che").click(function () {
    $(".line-gg").stop().animate({ left: "0px", width: "93px" }, 350);
    $(".line-vv").stop().animate({ left: "0px", width: "93px" }, 350);
    $(".nix-one").css({ display: "block" });
    $(".nix-two").css({ display: "none" });
  });

  $(".dian").eq(1).hide();
  $(".dian")
    .eq(0)
    .click(function () {
      $(".main-left").width(100);
      $(".dian").eq(1).show();
      $(this).hide();
    });
  $(".dian")
    .eq(1)
    .click(function () {
      $(".main-left").width(20);
      $(".dian").eq(0).show();
      $(this).hide();
    });
  $(".search-type li").click(function () {
    $(this).addClass("file").siblings().removeClass("file");
  });
  $("#punss li")
    .eq(1)
    .mouseover(function () {
      $(".line").stop().animate({ left: "91px", width: "93px" }, 350);
      $(".enrers-two").css({ display: "block" });
      $(".enrers-one").css({ display: "none" });
    });
  $("#punss li")
    .eq(0)
    .mouseover(function () {
      $(".line").stop().animate({ left: "0px", width: "72px" }, 350);
      $(".enrers-two").css({ display: "none" });
      $(".enrers-one").css({ display: "block" });
    });

  $(".cpenters li")
    .eq(1)
    .mouseover(function () {
      $(".line-io").stop().animate({ left: "91px", width: "72px" }, 350);
      $(".enrers-four").css({ display: "block" });
      $(".enrers-three").css({ display: "none" });
    });
  $(".cpenters li")
    .eq(0)
    .mouseover(function () {
      $(".line-io").stop().animate({ left: "0px", width: "72px" }, 350);
      $(".enrers-four").css({ display: "none" });
      $(".enrers-three").css({ display: "block" });
    });

  $(".enrers li")
    .eq(1)
    .mouseover(function () {
      $(".line-cc").stop().animate({ left: "91px", width: "36px" }, 350);
      $(".enrers-six").css({ display: "block" });
      $(".enrers-five").css({ display: "none" });
      $(".enrers-seven").css({ display: "none" });
    });
  $(".enrers li")
    .eq(0)
    .mouseover(function () {
      $(".line-cc").stop().animate({ left: "0px", width: "72px" }, 350);
      $(".enrers-six").css({ display: "none" });
      $(".enrers-five").css({ display: "block" });
      $(".enrers-seven").css({ display: "none" });
    });
  $(".enrers li")
    .eq(2)
    .mouseover(function () {
      $(".line-cc").stop().animate({ left: "180px", width: "81px" }, 350);
      $(".enrers-six").css({ display: "none" });
      $(".enrers-five").css({ display: "none" });
      $(".enrers-seven").css({ display: "block" });
    });
  $(".section li")
    .eq(0)
    .mouseover(function () {
      $(".line-oo").stop().animate({ left: "0px", width: "72px" }, 350);
      $(".focus_twos").css({ display: "none" });
      $(".focus_news").css({ display: "block" });
    });
  $(".section li")
    .eq(1)
    .mouseover(function () {
      $(".line-oo").stop().animate({ left: "91px", width: "72px" }, 350);
      $(".focus_news").css({ display: "none" });
      $(".focus_twos").css({ display: "block" });
    });
  $(".section-tab-cc  li")
    .eq(0)
    .mouseover(function () {
      $(".line-pp").stop().animate({ left: "0px", width: "72px" }, 350);
      $(".new-launch-two").css({ display: "none" });
      $(".new-launch-one").css({ display: "block" });
    });
  $(".section-tab-cc  li")
    .eq(1)
    .mouseover(function () {
      $(".line-pp").stop().animate({ left: "91px", width: "108px" }, 350);
      $(".new-launch-two").css({ display: "block" });
      $(".new-launch-one").css({ display: "none" });
    });

  $("#zu").click(function () {
    axios
      .get("http://jx.xuzhixiang.top/ap/api/reg.php", {
        params: {
          username: $("input").eq(0).val(),
          password: $("input").eq(1).val(),
        },
      })
      .then((resData) => {
        console.log(resData);
        let data = resData.data;
        if (data.code == 0) {
          alert("用户名已存在，请重试");
          // console.log("ok");
        } else {
          alert("注册成功");
          // location.href = "index.html";
        }
      });
  });

  $("#jin").click(function () {
    axios
      .get("http://jx.xuzhixiang.top/ap/api/login.php", {
        params: {
          username: $(".namez").val(),
          password: $(".mima").val(),
        },
      })
      .then((resData) => {
        let data = resData.data;
        localStorage.setItem("uid", data.data.id);
        localStorage.setItem("username", data.data.username);
        console.log(data);
        alert("登录成功");
        location.href = "index.html";
      });
  });

  if (localStorage.getItem("username")) {
    let username = localStorage.getItem("username");
    $(".register").text(username).next("#tui").text("退出");
  }

  $("#tui").click(function () {
    $(".register").text("登录").next("#tui").text("");
  });
  axios
    .get("http://jx.xuzhixiang.top/ap/api/allproductlist.php", {
      params: {
        // pagesize: 6,
        // pagenum: 1,
        uid: localStorage.getItem("uid") || 134148,
      },
    })
    .then((resData) => {
      console.log(resData.data.data);
      let conn = 0;
      let str = "";
      let data = resData.data.data.reverse();
      data.forEach((item) => {
        conn++;
        str += `
      <li class="ol-list">
      <div class="hut">
          <em class="firs">1</em
          ><a class="rank-title" href="detail.html?pid=${item.pid}">${item.pname}</a
          ><span>￥${item.pprice}</span>
        </div>
        <div class="rank-t">
          <a class="in1" href="detail.html?pid=${item.pid}"><img src="${item.pimg}" alt="" /></a>
          <div class="item-show">
            <a class="in2" href="detail.html?pid=${item.pid}"
              ><img src="img/jd.png" alt="" />¥${item.pprice}</a
            >
          </div>
        </div>
      </li>
      `;
      });
      $(".hot-list").html(str);

      // axios.get("http://jx.xuzhixiang.top/ap/api/add-product.php", {
      //   uid: $(),
      //   pid: $(),
      //   pnum: $(),
      // });

      $(".hot-list li:first-child").addClass("wid");

      $(".hot-list li").mouseover(function () {
        $(this)
          .find("span")
          .hide()
          .end()
          .addClass("wid")
          .siblings()
          .removeClass("wid");
      });
      $(".hot-list li").mouseout(function () {
        $(this).find("span").show();
      });
    });
});
